import matplotlib.pyplot as plt
import numpy as np
from process import utils

y1 = [9.82, 10.93, 11.96, 13.25]
y2 = [9.53, 11.07, 12.13, 14.25]
y3 = [8.82, 9.56, 10.94, 12.23]
y4 = [8.76, 9.96, 10.64, 12.03]

aRR_y1 = [[10.38, 9.26, 9.16, 10.48, 9.56, 10.08, 9.83, 9.81, 10.64, 9.0, 10.33, 9.31, 9.67, 9.97, 10.58, 9.06, 10.76, 8.88, 9.54, 10.1, 10.23, 9.41, 10.63, 9.01, 9.33, 10.31, 10.65, 8.99, 9.05, 10.59], [11.54, 10.32, 10.18, 11.68, 10.72, 11.14, 10.69, 11.17, 11.1, 10.76, 10.75, 11.11, 10.21, 11.65, 9.94, 11.92, 10.36, 11.5, 10.07, 11.79, 10.38, 11.48, 10.25, 11.61, 11.02, 10.84, 10.58, 11.28, 11.29, 10.57], [11.96, 11.96, 11.96, 11.96, 11.96, 11.96, 11.96, 11.96, 11.96, 11.96, 11.96, 11.96, 11.96, 11.96, 11.96, 11.96, 11.96, 11.96, 11.96, 11.96, 11.96, 11.96, 11.96, 11.96, 11.96, 11.96, 11.96, 11.96, 11.96, 11.96], [13.13, 13.37, 12.87, 13.63, 13.38, 13.12, 12.64, 13.86, 13.58, 12.92, 14.09, 12.41, 13.19, 13.31, 13.46, 13.04, 13.59, 12.91, 13.55, 12.95, 13.57, 12.93, 13.56, 12.94, 13.72, 12.78, 13.74, 12.76, 12.73, 13.77]]
aRR_y2 = [[9.39, 9.67, 10.32, 8.74, 10.19, 8.87, 9.01, 10.05, 9.55, 9.51, 10.02, 9.04, 8.78, 10.28, 10.43, 8.63, 8.54, 10.52, 8.95, 10.11, 9.4, 9.66, 9.51, 9.55, 8.56, 10.5, 9.62, 9.44, 9.87, 9.19], [9.36, 12.78, 12.19, 9.95, 10.83, 11.31, 11.6, 10.54, 12.54, 9.6, 12.25, 9.89, 9.34, 12.8, 10.49, 11.65, 11.75, 10.39, 12.57, 9.57, 11.7, 10.44, 12.54, 9.6, 12.65, 9.49, 11.73, 10.41, 10.35, 11.79], [11.49, 12.77, 12.04, 12.22, 13.52, 10.74, 13.73, 10.53, 10.96, 13.3, 11.83, 12.43, 10.87, 13.39, 10.95, 13.31, 14.04, 10.22, 11.97, 12.29, 10.42, 13.84, 12.3, 11.96, 11.63, 12.63, 14.1, 10.16, 12.33, 11.93], [14.73, 13.77, 14.68, 13.82, 13.43, 15.07, 14.35, 14.15, 13.41, 15.09, 13.45, 15.05, 13.46, 15.04, 13.48, 15.02, 13.82, 14.68, 14.34, 14.16, 14.27, 14.23, 13.44, 15.06, 15.11, 13.39, 15.25, 13.25, 15.02, 13.48]]
aRR_y3 = [[9.38, 8.26, 9.78, 7.86, 8.36, 9.28, 9.48, 8.16, 9.66, 7.98, 8.13, 9.51, 8.85, 8.79, 9.38, 8.26, 9.66, 7.98, 8.5, 9.14, 9.5, 8.14, 8.3, 9.34, 8.44, 9.2, 8.04, 9.6, 8.12, 9.52], [10.46, 8.66, 9.33, 9.79, 10.21, 8.91, 9.7, 9.42, 9.11, 10.01, 10.43, 8.69, 8.95, 10.17, 9.7, 9.42, 9.96, 9.16, 8.82, 10.3, 10.48, 8.64, 9.56, 9.56, 8.9, 10.22, 9.13, 9.99, 10.03, 9.09], [11.7, 10.18, 9.28, 12.6, 9.42, 12.46, 12.57, 9.31, 10.65, 11.23, 12.91, 8.97, 11.02, 10.86, 11.78, 10.1, 10.01, 11.87, 9.53, 12.35, 11.02, 10.86, 9.86, 12.02, 10.85, 11.03, 9.78, 12.1, 10.98, 10.9], [11.04, 13.42, 10.32, 14.14, 11.38, 13.08, 13.5, 10.96, 10.69, 13.77, 13.53, 10.93, 11.33, 13.13, 11.11, 13.35, 11.18, 13.28, 13.77, 10.69, 11.57, 12.89, 11.35, 13.11, 12.9, 11.56, 11.15, 13.31, 10.23, 14.23]]
aRR_y4 = [[9.24, 8.28, 8.75, 8.77, 8.85, 8.67, 9.41, 8.11, 9.75, 7.77, 8.2, 9.32, 8.33, 9.19, 9.46, 8.06, 7.81, 9.71, 8.47, 9.05, 8.48, 9.04, 9.02, 8.5, 9.76, 7.76, 9.66, 7.86, 9.27, 8.25], [10.62, 9.3, 9.16, 10.76, 10.1, 9.82, 10.49, 9.43, 9.7, 10.22, 10.85, 9.07, 10.17, 9.75, 9.37, 10.55, 9.3, 10.62, 9.68, 10.24, 9.49, 10.43, 9.04, 10.88, 9.39, 10.53, 10.86, 9.06, 10.57, 9.35], [11.59, 9.69, 9.43, 11.85, 9.67, 11.61, 9.25, 12.03, 10.49, 10.79, 9.18, 12.1, 11.2, 10.08, 12.25, 9.03, 12.3, 8.98, 12.49, 8.79, 9.02, 12.26, 10.36, 10.92, 10.36, 10.92, 9.56, 11.72, 9.55, 11.73], [13.01, 11.05, 11.76, 12.3, 12.77, 11.29, 13.24, 10.82, 12.97, 11.09, 13.35, 10.71, 11.02, 13.04, 12.61, 11.45, 14.01, 10.05, 10.47, 13.59, 12.1, 11.96, 10.2, 13.86, 12.07, 11.99, 11.24, 12.82, 12.68, 11.38]]

np.random.seed(12)
ar = np.array(y1)
aRR = [] # 存放结果
for i in range(ar.shape[0]):
    CONST = np.random.randint(0, 2)  # 浮动大小，就是[平均值-CONST, 平均值+CONST]之间的随机数
    tmp = []
    num = 30
    for j in range(num // 2):
        tmp.extend(utils.float_random(ar[i], ar[i] - CONST, ar[i] + CONST)) # 每次生成2个随机数
    aRR.append(tmp)
    # print(np.mean(np.array(tmp)))

np.savetxt("./csv/figure12c.csv", aRR, delimiter=",", fmt="%.2f")
print(aRR)


x = [2,3,4,5]

aRR_std1 = np.std(aRR_y1,axis=1)
aRR_std2 = np.std(aRR_y2,axis=1)
aRR_std3 = np.std(aRR_y3,axis=1)
aRR_std4 = np.std(aRR_y4,axis=1)

plt.plot(x, y1, 'bo-', markersize=8, label='LDC-COR')
plt.plot(x, y2, 'gv--', color='#00FF00', markersize=8, label='LDC-OR')
plt.plot(x, y3, 'r^--', markersize=8, label='LDC-ACOR')
plt.plot(x, y4, 'ks--', color='black', markersize=8, label='LDC-AOR')

plt.errorbar(x, y1, yerr=aRR_std1, fmt="bo-", color="blue", elinewidth=2, capsize=6,markersize=8)
plt.errorbar(x, y2, yerr=aRR_std2, fmt="v--", color='#00FF00', elinewidth=2, capsize=6,markersize=8)
plt.errorbar(x, y3, yerr=aRR_std3, fmt='r^--', elinewidth=2, capsize=4, markersize=8)
plt.errorbar(x, y4, yerr=aRR_std4, fmt='ks--', elinewidth=2, capsize=4, markersize=8)

plt.xticks([2,2.5,3,3.5,4,4.5,5], fontsize='14')
plt.yticks([9,9,10,11,12,13,14,15], fontsize='14')
plt.grid(linewidth=0.4, color='#DFDFDF')
plt.xlabel('K', fontsize=18)
plt.ylabel('Energy Cost(W)', fontsize=18)
# plt.legend(['LDC-COR', 'LDC-OR', 'LDC-ACOR', 'LDC-AOR', 'AVERAGE'], loc='upper left', fontsize=14)
plt.legend(['LDC-COR', 'LDC-OR', 'LDC-ACOR', 'LDC-AOR'], loc='upper left', fontsize=14)

plt.tight_layout()
plt.savefig('./eps/figure12c.eps', dpi=600, format='eps')
plt.show()